package com.aphidmobile.flip.demo.adapter;

import java.util.ArrayList;
import java.util.List;

import org.zeroxlab.widget.AnimationLayout;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ListView;

import com.aphidmobile.flip.demo.data.Travels;
import com.aphidmobile.utils.UI;
import com.example.menu.activity.Dangnhap;
import com.example.muachung.DealDuocThich2;
import com.example.muachung.R;
import com.smartservice.ui.custom_lv_adapters.lvAdapterMenu;

public class TravelAdapter extends BaseAdapter {

  private LayoutInflater inflater;
  private Context mContext;
  private int repeatCount = 1;

  private List<Travels.Data> travelData;

  public TravelAdapter(Context context) {
    inflater = LayoutInflater.from(context);
    travelData = new ArrayList<Travels.Data>(Travels.IMG_DESCRIPTIONS);
    this.mContext = context;
  }

  @Override
  public int getCount() {
    return travelData.size() * repeatCount;
  }

  public int getRepeatCount() {
    return repeatCount;
  }

  public void setRepeatCount(int repeatCount) {
    this.repeatCount = repeatCount;
  }

  @Override
  public Object getItem(int position) {
    return position;
  }

  @Override
  public long getItemId(int position) {
    return position;
  }

  @SuppressLint("InflateParams")
@Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View layout = convertView;
    ListView lv_menu;
    final AnimationLayout mLayout;
    if (convertView == null) {
      layout = inflater.inflate(R.layout.activity_home, null);
    //  AphidLog.d("created new view from adapter: %d", position);
    }

    final Travels.Data data = travelData.get(position % travelData.size());

	mLayout = (AnimationLayout) layout.findViewById(R.id.animation_layout);
	//mLayout.setListener(this);

	// Creating menu list
	lv_menu = (ListView) layout.findViewById(R.id.lv_menu);
	lvAdapterMenu mAdapter = new lvAdapterMenu(mContext);

	// add item for main menu
	mAdapter.addItem("Đăng nhập");
	//mAdapter.addImageItem(R.drawable.img_btn_menu);
	mAdapter.addSeparatorItem("Danh mục");
	mAdapter.addItem("Deal Được thích");
//	mAdapter.addImageItem(R.drawable.img_btn_back);
	mAdapter.addItem("Quản lý đơn hàng");
	mAdapter.addItem("Sửa địa chỉ nhập hàng");
	mAdapter.addItem("Lịch sử ví mua chung");
	mAdapter.addItem("Điểm thưởng");
	mAdapter.addItem("Nạp tiền");
	mAdapter.addSeparatorItem("Hệ thống");
	mAdapter.addItem("Sắp xếp Deal");
	mAdapter.addItem("Thoát");
	lv_menu.setAdapter(mAdapter);
	lv_menu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub

			 if(arg2==0){
				 Intent intentDangNhap=new Intent(mContext,Dangnhap.class);
				 mContext.startActivity(intentDangNhap);
			 }
			 if(arg2==2){
				 Intent intentDealDuocThich=new Intent(mContext,DealDuocThich2.class);
				 mContext.startActivity(intentDealDuocThich);
			 }
			 if(arg2==3){
				 Intent intentDangNhap=new Intent(mContext,Dangnhap.class);
				 mContext.startActivity(intentDangNhap);
			 }
			 if(arg2==4){
				 Intent intentDangNhap=new Intent(mContext,Dangnhap.class);
				 mContext.startActivity(intentDangNhap);
			 }
			 if(arg2==5){
				 Intent intentDangNhap=new Intent(mContext,Dangnhap.class);
				 mContext.startActivity(intentDangNhap);
			 }
			 if(arg2==6){
				 Intent intentDangNhap=new Intent(mContext,Dangnhap.class);
				 mContext.startActivity(intentDangNhap);
			 }
			 if(arg2==7){
				 Intent intentDangNhap=new Intent(mContext,Dangnhap.class);
				 mContext.startActivity(intentDangNhap);
			 }
			 if(arg2==8){
				 Intent intentDangNhap=new Intent(mContext,Dangnhap.class);
				 mContext.startActivity(intentDangNhap);
			 }
			 if(arg2==9){
				 Intent intentDangNhap=new Intent(mContext,Dangnhap.class);
				 mContext.startActivity(intentDangNhap);
			 }
			 if(arg2==10){
				    Intent intent = new Intent(Intent.ACTION_MAIN);
				    intent.addCategory(Intent.CATEGORY_HOME);
				    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				    mContext.startActivity(intent);
			 }
				 
		}
	});
//    UI
//        .<TextView>findViewById(layout, R.id.title)
//        .setText(AphidLog.format("%d. %s", position, data.title));
//
//    UI
//        .<ImageView>findViewById(layout, R.id.photo)
//        .setImageBitmap(IO.readBitmap(inflater.getContext().getAssets(), data.imageFilename));
//
//    UI
//        .<TextView>findViewById(layout, R.id.description)
//        .setText(Html.fromHtml(data.description));
//
    UI
        .<ImageButton>findViewById(layout, R.id.btn_toogle)
        .setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
//            Intent intent = new Intent(
//                Intent.ACTION_VIEW,
//                Uri.parse(data.link)
//            );
//            inflater.getContext().mContext.startActivity(intent);
        	//  Toast.makeText(getAp, "this is my Toast message!!! =)",Toast.LENGTH_LONG).show();
        	  mLayout.toggleSidebar();
          }
        });

    return layout;
  }

//  public void removeData(int index) {
//    if (travelData.size() > 1) {
//      travelData.remove(index);
//    }
//  }
}
